//
//  ViewController.m
//  ActionsMemorandum
//
//  Created by _LJX on 2017/10/26.
//  Copyright © 2017年 _LJX. All rights reserved.
//

#import "ViewController.h"
#import "SingleModle.h"
#import "UploadData.h"
#import "MemorandumModle.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *MemorandumTableView;

@end

@implementation ViewController
- (IBAction)NewMemorandum:(id)sender {
    UIViewController *lv = [[NSBundle mainBundle]loadNibNamed:@"NewMemorandum" owner:nil options:nil].firstObject;
    [self presentViewController:lv animated:YES completion:nil];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  [SingleModle shareData].DataCache.count;
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *TableSampleIdentifier = @"TableSampleIdentifier";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                             TableSampleIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleSubtitle
                reuseIdentifier:TableSampleIdentifier];
        
    }
    MemorandumModle *mem =[[MemorandumModle alloc]initWithDict:[SingleModle shareData].DataCache[indexPath.row]];
    cell.textLabel.text =mem.title;
    cell.detailTextLabel.text = mem.time;
    return cell;
    

}





-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [SingleModle shareData].cutternIndex = indexPath.row;
    [SingleModle shareData].cutternMem = [[MemorandumModle alloc]initWithDict:[SingleModle shareData].DataCache[indexPath.row]];
    UIViewController *lv = [[NSBundle mainBundle]loadNibNamed:@"MemorandumShow" owner:nil options:nil].firstObject;
    [self presentViewController:lv animated:YES completion:nil];
}




-(void)viewWillAppear:(BOOL)animated{
    NSLog(@"返回界面刷新");
    [self.MemorandumTableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [UploadData CreatStorageFile];
    [UploadData WriteData];
    [UploadData ReadData];
    [SingleModle shareData].mArr = [[NSMutableArray alloc]init];
    for (NSArray *arr in [SingleModle shareData].DataCache) {
        [[SingleModle shareData].mArr addObject:arr];
    }
    NSLog(@"view 加载");
    NSLog(@"%@",[SingleModle shareData].DataCache);
    
    /*
#pragma test
    NSFileManager *fileManager = [[NSFileManager alloc]init];
    NSString *pathDocuments = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
    NSString *createPath = [NSString stringWithFormat:@"%@/MemorandumData.plist",pathDocuments];
    if (![[NSFileManager defaultManager]fileExistsAtPath:createPath]) {
        [fileManager createFileAtPath:createPath contents:nil attributes:nil];//创建文件
        //        [fileManager createDirectoryAtPath:createPath withIntermediateDirectories:YES attributes:nil error:nil];//创建文件夹
        NSLog(@"创建成功");
    }else{
        NSLog(@"有这个文件了");
    }
    NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:@"dsa",@"title",@"dsa",@"article",@"dsa",@"time",nil];
    NSDictionary *dic1 = [[NSDictionary alloc]initWithObjectsAndKeys:@"66666",@"title",@"558555",@"article",@"0000",@"time",nil];
    NSDictionary *dic2 = [[NSDictionary alloc]initWithObjectsAndKeys:@"15555",@"title",@"dsa",@"article",@"0000",@"time",nil];
    NSArray *arr = [[NSArray alloc]initWithObjects:dic,dic1,dic2, nil];
    [arr writeToFile:createPath atomically:YES];
    NSArray *arr1 = [NSArray arrayWithContentsOfFile:createPath];
    [SingleModle shareData].DataCache = arr1;
    */
    
    
    // Do any additional setup after loading the view, typically from a nib.

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
